|
|
View previous topic - View next topic |
Author |
Message |
mandrake_lazy Guest
|
Posted: Tue Jun 22, 2004 3:42 pm Post subject: pssssst bjorn |
[quote] |
|
hey bjorn, you rock with a sock when it comes to Lua, or so I've heard....I have a question-> if I where to call a script in Lua, and I wanted to have some variables sent to it as global varaibles, would all I have to do is just push these varaibles onto the stack?
EDIT:
whoops. sorry about the name spelling.
|
|
Back to top |
|
|
Bjorn Demon Hunter
Joined: 29 May 2002 Posts: 1425 Location: Germany
|
Posted: Tue Jun 22, 2004 10:37 pm Post subject: |
[quote] |
|
I think you can just set the globals before calling the script... There is a table holding the globals, I think it's called _G. Grab a reference to the table, then set your globals in the table. This can all be done using the C API. When you're done, call the script.
We'll see if I rock with a sock. :P
If that's too complicated, what about executing a dynamically created string like:
Code: | lua_State *L = lua_open();
char *script = new char[32];
int varValue = 56;
snprintf(script, 32, "globalVarName = %d\n", varValue);
lua_dostring(L, script); |
Though I think it's quite ugly. :)
Last edited by Bjorn on Tue Jun 22, 2004 10:49 pm; edited 1 time in total
|
|
Back to top |
|
|
biggerUniverse Mage
Joined: 18 Nov 2003 Posts: 326 Location: A small, b/g planet in the unfashionable arm of the galaxy
|
Posted: Tue Jun 22, 2004 10:45 pm Post subject: |
[quote] |
|
I heard he was rocking with a stocking... but I don't know if that's the same thing... _________________ We are on the outer reaches of someone else's universe.
|
|
Back to top |
|
|
Bjorn Demon Hunter
Joined: 29 May 2002 Posts: 1425 Location: Germany
|
Posted: Tue Jun 22, 2004 11:01 pm Post subject: |
[quote] |
|
Figured it out from the manual, this should do it:
Code: | lua_pushstring(L, "globalVarName");
lua_pushnumber(L, varValue);
lua_settable(L, LUA_GLOBALSINDEX); |
Notice also that in lua.h, there is a convenience function to set global variables:
Code: | #define lua_setglobal(L,s) \
(lua_pushstring(L, s), lua_insert(L, -2), lua_settable(L, LUA_GLOBALSINDEX)) |
Which can be used as follows:
Code: | lua_pushnumber(L, varValue);
lua_setglobal(L, "globalVarName"); |
lua.h and lauxlib.h contain quite a bit of convenience functions that are not in the manual, you should check them out.
|
|
Back to top |
|
|
Mandrake elementry school minded asshole
Joined: 28 May 2002 Posts: 1341 Location: GNARR!
|
Posted: Wed Jun 23, 2004 3:52 am Post subject: |
[quote] |
|
I think I will actually. Thanks, the help is much appriciated. I'm working on doing some scripting for teh Changeling- originally I was going to do it in Python, but Python is not very easy to use to extend a program (although extending Python with C is easy, but extending C with Python is not...agh. What a mess). And Lua, from what I had used earlier, seemed to be very simple to get up and running. _________________ "Well, last time I flicked on a lighter, I'm pretty sure I didn't create a black hole."-
Xmark
http://pauljessup.com
|
|
Back to top |
|
|
|
Page 1 of 1 |
All times are GMT
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|