Rici Lake | 1 Mar 03:13 2007
Picon

Re: SWIG question


On 28-Feb-07, at 1:50 PM, Brian Hassink wrote:

> Actually, in looking at this some more it appears as though it's not
> possible to put a lua_yield() call within a SWIG wrapped function.  The
> semantics of a SWIG wrapped function are different from that of a
> lua_CFunction.
>
> So, how would one do something like...
>
> 	result = block(self, event)
>
> ...where block() is a SWIG wrapped function that takes the script
> context (i.e. state) and an event as arguments, and blocks (yields) the
> script until the event occurs, after which the details are copied into 
> a
> result structure (resumes)?
>

I don't know a lot about SWIG (and it may not be the optimal binding
system for you, in fact, but that's another issue).

However, it seems like the easiest solution is to write block() in
Lua. There's no shame in that :)

function block(event) return coroutine.yield(event) end

That assumes that you have a supervisor (event loop, I guess)
which handles the coroutines. You could write this in Lua,
as well; I've put an example on the wiki at 
(Continue reading)

gary ng | 1 Mar 04:02 2007
Picon

Re: SWIG question


--- Rici Lake <lua <at> ricilake.net> wrote:
> That assumes that you have a supervisor (event loop,
> I guess) which handles the coroutines. You could 
>write this  in Lua,as well; I've put an example on 
>the wiki at
>http://lua-users.org/wiki/CoroutinesAsEventHandlers
I am struggling with this supervisor issue. For many
cases, there is no need for copas(or at least the
semantics don't fit). Yet sending/receiving through
either a pipe or socket is a basic need for many
applications.

This would create a problem of, what supervisor to
use(or how to coop the supervisors). Take this
supervisor as an example, how can I make it work with
copas(as copas handles io/socket related
block/resume/yield which I don't want to re-invent).

 
____________________________________________________________________________________
We won't tell. Get more on shows you hate to love 
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265 

Rici Lake | 1 Mar 04:29 2007
Picon

Re: SWIG question


On 28-Feb-07, at 10:02 PM, gary ng wrote:

>
> --- Rici Lake <lua <at> ricilake.net> wrote:
>> That assumes that you have a supervisor (event loop,
>> I guess) which handles the coroutines. You could
>> write this  in Lua,as well; I've put an example on
>> the wiki at
>> http://lua-users.org/wiki/CoroutinesAsEventHandlers
> I am struggling with this supervisor issue. For many
> cases, there is no need for copas(or at least the
> semantics don't fit). Yet sending/receiving through
> either a pipe or socket is a basic need for many
> applications.
>
> This would create a problem of, what supervisor to
> use(or how to coop the supervisors). Take this
> supervisor as an example, how can I make it work with
> copas(as copas handles io/socket related
> block/resume/yield which I don't want to re-invent).

Well, that supervisor (which hasn't been very heavily
tested yet :) ) is written to work as a coroutine
itself. So you should be able to use it as a delegate
driven by some other supervisor; at least, that was
the idea.

gary ng | 1 Mar 11:00 2007
Picon

writable "string" ?

Hi,

I want to implement some file buffering system which
can range from say 32K to 512K and the read/write
pattern is typical like write(f, offset, size) where
the size is usually 4k to 16k, or may be even smaller.

It seems that keeps on re-constructing the string
would be very in-efficient, so is using a table to
store individual char(as string or number).

I want to just write a simple C function which takes
the passed in "lua string" and use memcpy to overwrite
the desired range.

Is this doable or are their any concern ?

thanks and regards,

gary

 
____________________________________________________________________________________
Never Miss an Email
Stay connected with Yahoo! Mail on your mobile.  Get started!
http://mobile.yahoo.com/services?promote=mail

Picon

Re: writable "string" ?

> It seems that keeps on re-constructing the string
> would be very in-efficient, so is using a table to
> store individual char(as string or number).

Try ropes. See http://lua-users.org/wiki/LuaRopes .
--lhf

gary ng | 1 Mar 11:52 2007
Picon

Re: writable "string" ?


--- Luiz Henrique de Figueiredo
<lhf <at> tecgraf.puc-rio.br> wrote:

> > It seems that keeps on re-constructing the string
> > would be very in-efficient, so is using a table to
> > store individual char(as string or number).
> 
> Try ropes. See http://lua-users.org/wiki/LuaRopes .
> --lhf
> 
Thanks but that doesn't seem to be what I want. I am
actually not constructing string from pieces but just
use string as block buffer which only needs simple
file type read/write access(sort of in memory file).

 
____________________________________________________________________________________
Bored stiff? Loosen up... 
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front

Eike Decker | 1 Mar 12:10 2007
Picon

Debugging luacode => efficient file name retrieval?

Hi

I am trying to develop an IDE for Luxinia, a 3D engine that is using lua for
pretty much anything (http://www.luxinia.de). Performance is a critical key
here, but lua does a good job on that.

However, debugging the luacode is not very joyful at the moment. I am testing
here a project which is using quite alot of luacode and I have an average
performance of about 280 FPS without debugging. If I switch on the hookfunction
in "cr" mode (called on lua function calls / returns), I get about 200-240 fps,
so no real loss. 
But if I try to find out which file is currently in use I fall to 1-2 fps (using
debug.getinfo). After optimizing parts of it, it raised to 7-8 fps. Then I had
the idea to let the hook function retrieve the filename as third argument.
Well, this works better - 30-40 fps. But still pretty bad compared to the
original performance (about 10%). I added an optional argument that limits
calling the hookfunction only if the file of execution seems to have changed.

I copied pieces of code from the ldebug.c file in my project and the way I am
retrieving the filename looks like this right now:

//lua_getstack(L, 1, ar); 
    ar->i_ci =  L->ci-1-L-≥base_ci; // instead of above - bad idea?
    if (ar->i_ci != 0)
    {
		CallInfo *ci = NULL;
		Closure *cl = NULL;
		ci = L->base_ci + ar->i_ci;
		lua_assert(ttisfunction(ci->func));
		cl = clvalue(ci->func);
(Continue reading)

Timm Felden | 1 Mar 12:11 2007

Linking values to lua with set/get

Is there a way of writing a function "lua_link( name, set, get );", that 
would do this:
lua:  name = <any value(s)>
-> invokes the parameter passed as set, this is like the normal C-functions

lua: x = name
-> invokes set, which is also a normal C-function, but by default gets 
no parameters and returns only one.

I ask, because I have to take care of values between lua and C and atm 
I'm using functions, what is pretty ugly:P

Timm Felden

Eike Decker | 1 Mar 12:21 2007
Picon

Re: writable "string" ?

Hi

Lua calculates a hash value for strings in order to improve the speed for
comparing two strings. If you change the string inside of C, the hash value
won't be valid anymore. The hashvalue is used for comparing strings or storing
strings in tables as keys (as far as I know).

You could also write a C userdata object that allows you to create a buffer that
you can manipulate. Of course this would require you to write your own functions
to search patterns and so on, so this would be quite some work... 

Eike

> Hi,
> 
> I want to implement some file buffering system which
> can range from say 32K to 512K and the read/write
> pattern is typical like write(f, offset, size) where
> the size is usually 4k to 16k, or may be even smaller.
> 
> It seems that keeps on re-constructing the string
> would be very in-efficient, so is using a table to
> store individual char(as string or number).
> 
> I want to just write a simple C function which takes
> the passed in "lua string" and use memcpy to overwrite
> the desired range.
> 
> Is this doable or are their any concern ?
> 
(Continue reading)

Kein-Hong Man | 1 Mar 12:53 2007
Picon

Re: Debugging luacode => efficient file name retrieval?

Eike Decker wrote:
> [snip]
> However, debugging the luacode is not very joyful at the moment. [snip]
> This piece of code is responsible for the loss of about 120FPS - so it would be
> required to be much more efficient...
> I already took ripped out the essential parts from other functions instead of
> calling them in order to get more performance though I am not sure if that will
> break something there...
> 
> I'd be happy for any advice to make this work faster. 

My 2 cents. Given what was written in Lua's manual.html, I'd 
question whether your app should be using those debug functions so 
extensively in the first place, especially for the kind of app 
you're running. I thought those functions are used sparingly, say 
in a gdb-like setting, but they are not for running full-bore 
providing a program trace. Don't call or hook anything unless you 
absolutely need it.

> The only thing I can imagine, make a list of lines that contain lists of files
> they belong to - and check then only the lines that are matching...

I hope you're not putting effort optimizing the wrong things...

HTH,
--

-- 
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia

(Continue reading)


Gmane