Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


spek

Member Since 11 Apr 2005
Offline Last Active Yesterday, 03:58 PM

Posts I've Made

In Topic: Implementing (Lua) Script efficiently

28 June 2015 - 03:08 PM

All right. I wasn't able to implement this with success, but that is merely my lack of experience with Lua. Reading/pushing/popping the stack incorrectly, its a bit confusing. I should be learning some basics first. But anyhow, you explained the possibilities, so I have some targets to work towards. Thanks!


In Topic: Implementing (Lua) Script efficiently

28 June 2015 - 11:14 AM

Thanks a ton for this code example.

 

Yet, wouldn't this "per file" approach create a lot of overhead memory-wise, as I have to add some basic functions/types and register the API (a big collection of functions from the host that can be called in the script) for each file? Now in practice I don't think each and every diferent object will override all of its events with a scripted function, but several hundreds of files wouldn't surprise me.

 

Being able to put all events per object into a single file would reduce the amount quite a lot already (plus makes more sense from a editing / management perspective). Can the same thing be done to get the id of a specific function within the file? So in this example, I would put both "sub" and "add" in the same file, then get the id of each function.

 

Cheers


In Topic: Implementing (Lua) Script efficiently

27 June 2015 - 03:06 PM

Did I say I knew enough, for now?

 

I've been looking around on calling Lua functions, using a table. But pretty much all examples I've found are using the lua_getGlobal function. Then again I'm very new to Lua so probably I just didn't search the right things.

 

To start with, who's going to fill this table (the host program, or the Lua script?) with these function addresses? If I understand it right, the table basically holds pointers to functions. So far I tried this:

sub = function(x, y)
  return x - y
end

add = function(x, y)
  return x + y
end

function makeFunctionTable()
  return {	
  		sub,
  		add
  	 }
end

On the host side, I would call "makeFunctionTable", and loop through the table. But... no idea if filling the table is correct, nor how to retreive the addresses. If I fill it with strings, I get strings properly. But in this case I have... pointers? lua_tointeger just gives zero's. And even if I would get a pointer, I have no idea how to use it later on to call a function.

 

 

Maybe there is an example somewhere?


In Topic: Implementing (Lua) Script efficiently

27 June 2015 - 05:42 AM

Ok, that's all I needed to know! (for now hehe)

 

Thanks again


In Topic: Implementing (Lua) Script efficiently

27 June 2015 - 01:44 AM

All right, makes sense. Precompiling / registering it will be. I'm still having doubts to follow route B or C. C is probably the most efficient, yet it requires to gather all code (from many different files) at the startup which takes some energy on itself. Well, that's just some management detail.

 

One last question though; does size matters when it comes to the execution speed of a (Lua) script. Does a script run slower if it contains thousands of functions (which will be the case if I gather all)? Not that I execute all those functions - I just call 1 event-, but maybe the script needs more time when calling another sub-function within that event? I guess it doesn't matter, but maybe I'm wrong.

 

Thanks!


PARTNERS