Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Moebius

#1
Python is a very powerful language, interesting in that nothing is statically typed.  Scripting support from within GLB would be interesting...
If you're interested in learning it, CS212 on Udacity is a very good course, and it gave me my favourite snippet:
Code (glbasic) Select

def memo(f):
   cache = dict()
   def wrap(*args):
      if args not in cache: cache[args] = f(*args)
      return cache[args]
   return wrap

memo:  A function that takes in a function, and returns a function that has an inbuilt cache that stores the results of previous calls.

so:
Code (glbasic) Select
f = lambda x: x**2
f = memo(f)
# or this achieves the same thing:
@memo
def f(x):
   return x**2
#2
Alright I couldn't get setlength() to work, but alloc(int,bool) does seem to work (where the second boolean parameter seems to specify whether to copy the old string across).
Thanks for that - hopefully things won't be broken by this!
#3
Yep it's easy get a pointer to the data, but how then do I allocate a buffer?  without GetStrData the only way I can think of getting a specific size DGStr is:
FOR i = 1 TO Size
   INC Buffer$, " "
NEXT
... which I can't see working very nicely or quickly :\

@Gernot (well anyone who knows the internal DGStr definition) is there another way I can allocate a string of a variable size?  Some special constructor?

(Slightly related, could GLB get around strings "like \0 this" by having a constructor take a c-string and a length?  That would be a lot easier than "like " + CHR$(0) + " this")
#4
The help file under INLINE mentions this function, but whenever I try to use it the compiler tells me that "class __GLBASIC__::DGStr has no member named 'GetStrData'".
Does the help file list the wrong name?  or what should I be using here?  Thanks.
#5
one thing that's bugged me when I've had to look at the CPP is that line numbers are handled by a #define and #undef per line - tripling the number of lines, but I'm not sure how much of an effect that has on compilation speed though...
#6
is there some simple way to get the address of the string data (for a DGStr) in INLINE code?
#7
The startup time isn't great, but you *might* be able to display a splash screen or prevent autolock by modifying the java code, but I'm not sure if anyone's succeeded yet.  Anyway it's not too bad that a native GUI is being developed first  =D

There's no way to use bluetooth with GLB commands, but using inline code and by modifying some of the java it should be possible - although I wouldn't know where to start...

On rescaling, I personally cheated and rendered everything to a 480x320 virtual screen (CREATESCREEN, USESCREEN, etc.), which I then rotate and display.  Code has been posted in the forums though - for instance http://www.glbasic.com/forum/index.php?topic=7145.0
#8
The first time your GLB app runs, all of the media files are copied out from the apk package - this takes a long while, but then afterwards your apps should start quite quickly.
A loading symbol or splash screen while the media files are copied *might* be implemented eventually (I'm not to sure on where this has gotten, but it isn't that much of a problem)
#9
Bug Reports / Re: IDE
2012-Jun-17
On #2 I get the same [for a lot of GLOBALs  :x]
It seems to occur if definitions of globalled variables are within functions...
#10
This is confusing.

I tried this code:
Code (glbasic) Select
LOCAL start=0
LOCAL stop=200000
LOCAL stepping=0.005

LOCAL time0#, value#, s$

FOR trials = 0 TO 2

value = 0
time0=GETTIMERALL()
FOR i=start TO stop STEP stepping
value=value+1
NEXT
time0=GETTIMERALL()-time0
STDOUT time0+" ms\n"


NEXT

STDOUT "\n\n"


FOR trials = 0 TO 2

value = 0
time0=GETTIMERALL()
FOR i=start TO stop STEP stepping
value=value+1
NEXT
time0=GETTIMERALL()-time0
s$ = value
STDOUT time0+" ms\n"

NEXT

KEYWAIT
END


This gives me around 100ms for the pure loop, and 140ms for the loop which has "s$ = value" afterwards...


However, running this code:
Code (glbasic) Select
LOCAL start=0
LOCAL stop=200000
LOCAL stepping=0.005

LOCAL time0#, value#, s$


value = 0
time0=GETTIMERALL()
FOR i=start TO stop STEP stepping
value=value+1
NEXT
time0=GETTIMERALL()-time0
STDOUT time0+" ms\n"


STDOUT "\n\n"

value = 0
time0=GETTIMERALL()
FOR i=start TO stop STEP stepping
value=value+1
NEXT
time0=GETTIMERALL()-time0
s$ = value
STDOUT time0+" ms\n"


KEYWAIT
END

(The same code just w/o the for loops), I get 115ms and 140ms....

Using kakonet's original code (i.e. using 'value=1' instead of 'value=value+1'), with both snippets left in as above, I get the same times (115ms, 140ms).
Running either snippet on their own I get these times...

Using 'value = SIN(1)' instead, I get something like 4495ms for the one without the string, and 4505ms for the one with the string assignment afterwards.

I have tried things like adding a DELAY at the start and rearranging things, but get the same results.
Go figure  :S
This seems like it has to do with optimisation, although I don't understand why things would turn out differently within for loops, or with a conversion to a string afterwards....
#11
I'm in favour of the external file - could we put that in the project directory and have GLB copy that across?  (like w/ icon.png?)
#13
Are you having port forwarding issues?  (Presuming you connect using a router, how have you set it up?  Sounds like the port is forwarded to your PC - so connecting to it works, but won't work on another device in your network...)
#14
I believe you'll find the command he meant is SETSCREEN  ;)
#15
Sounds good.  I guess we could mess with the code anyway if we really wanted too.  Isn't it funny that the difference between a blank screen and a series of moving "O"s is so large to a user?