Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,561 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Script interpreter for Lite-C [Re: nfs42] #433106
11/23/13 15:14
11/23/13 15:14
Joined: Mar 2010
Posts: 57
LemmyTheSlayer Offline
Junior Member
LemmyTheSlayer  Offline
Junior Member

Joined: Mar 2010
Posts: 57
here you go.
in the sample program you can open a console with tab and enter some lua code.
i created a sample lua function create_cube(x,y,z), which creates a cube at a given position (o rly? ya rly.)

for more information take a look at the official lua and luajit documentations


SCHLEIFE SCHLEIFE SCHLEIFE SCHLEIFE SCHLEIFE SCHLEIFE
Re: Script interpreter for Lite-C [Re: LemmyTheSlayer] #433351
11/28/13 12:53
11/28/13 12:53
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline OP
Member
TehV  Offline OP
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
Thanks! This is a great help!
EDIT: The script interpreter works, and I was able to define a few functions for use with the Lua language. I've run into two problems, though:
1. I can't seem to figure out how to return values from Lua functions. I've found that there's a function named lua_yield(lua_State* L, int numValues), but any attempt to use it results in an error for attempting to call an empty function.

Here's the relevant code:
Code:
int lua_gettimestep(lua_State* L) {
	lua_pushnumber(L,time_step);
	return lua_yield(L,1);
}
//...
function lua_init() {
	lua_register(L,"getTimeStep",lua_gettimestep);
}



Here's how I try to use it:
Code:
Lua console>> a = getTimeStep()



Here's the exact response I get (it opens a message window):
Code:
Empty function called in lua_gettimestep



2. Whenever one of my functions includes a wait(n) instruction, I get a script crash in that function. This is a problem, since I would like to allow users to use a wait(n) instruction.

Here's the relevant code:
Code:
int lua_wait(lua_State* L) {
	if (lua_gettop(L) == 0) {
		wait(1);
	} else {
		wait(lua_tonumber(L,1));
	}
	return 0;
}
//...
function lua_init() {
	lua_register(L,"sys_wait",lua_wait);
}



Here's how I try to use it:
Code:
Lua console>> sys_wait(3)



Here's the exact response I get (it opens a message window):
Code:
Script crash in lua_wait



EDIT2: I tried using the FFI libraries to import the wait() function from Gamestudio, and it errors because I attempt to use the data type 'var'. If I don't use it, it doesn't find the function.

In an attempt to work around this, I've imported the Sleep() function, and it does work, but it appears to freeze the entire program instead of just the script. This makes it useless for my purposes. Any ideas how I can fix this?

Last edited by TehV; 11/28/13 19:57.
Re: Script interpreter for Lite-C [Re: TehV] #433409
11/29/13 10:22
11/29/13 10:22
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline OP
Member
TehV  Offline OP
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
Needs more help!

Re: Script interpreter for Lite-C [Re: TehV] #433410
11/29/13 10:24
11/29/13 10:24
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
you can't use "wait" from external languages. it is some kind of dirty c magic that swaps the active function and thus destroys your c call stack.


Visit my site: www.masterq32.de
Re: Script interpreter for Lite-C [Re: MasterQ32] #433411
11/29/13 10:29
11/29/13 10:29
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline OP
Member
TehV  Offline OP
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
Okay, is there some way I can work around this? I'd like to allow my users to make use of the function...

Last edited by TehV; 11/29/13 10:30.
Re: Script interpreter for Lite-C [Re: TehV] #433414
11/29/13 11:18
11/29/13 11:18
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
nope, you can just create some kind of state machine in lua:

Code:
function loop2(sm)
  -- Idle here
end

function loop1(sm)
  sm.myTicks = sm.myTicks - 1
  if sm.myTicks < 0 then
    sm.update = loop2
  end
end

function init(sm)
  sm.myName = "Hello World"
  sm.myTicks = 16
  sm.update = loop1
end

sm = { }
sm.update = init



From Lite-C you call sm.update with sm as the argument. so you have an object that gets a flexible update every frame.
the system terminates if sm.update = nil

Last edited by MasterQ32; 11/29/13 11:18.

Visit my site: www.masterq32.de
Re: Script interpreter for Lite-C [Re: MasterQ32] #433418
11/29/13 11:57
11/29/13 11:57
Joined: Mar 2010
Posts: 120
Switzerland
T
TehV Offline OP
Member
TehV  Offline OP
Member
T

Joined: Mar 2010
Posts: 120
Switzerland
Well, that will have to do then. Thanks for the help!

Now I need to know how registered C functions can return data for use in Lua, and I should be well on my way.

I'd also like to know if it is possible for C to call Lua functions. Perhaps I could create a set of functions which allow a certain Lua function to be called at regular intervals (so would it be possible to define callback functions to create a timer, for example?)

Re: Script interpreter for Lite-C [Re: TehV] #433420
11/29/13 12:45
11/29/13 12:45
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
it's both possible. there is an entry for both parts in the lua documentation
http://www.lua.org/pil/25.2.html
http://www.lua.org/pil/26.html


Visit my site: www.masterq32.de
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1