Page 1 of 1

any one integrate Lua or other runtime scripting?

Posted: Sat Jan 07, 2012 1:01 am
by jassing
I need to integrate some runtime scripting in a service to allow for custom alerts to be provided.
Has anyone integrated Lua or other for runtime scripting?
I searched the forums for Lua but there was not one hit....

Re: any one integrate Lua or other runtime scripting?

Posted: Sat Jan 07, 2012 2:54 am
by Demivec

Re: any one integrate Lua or other runtime scripting?

Posted: Sun Jan 08, 2012 6:22 am
by jassing
Gave the lua52 example a try... it seems to crash for me...

Using a simple script: (test.lua) works fine in the lua interpreter.

Code: Select all

function test()
  os.execute("C:\\windows\\system32\\notepad.exe")
end
test()
However, using the example for the lua52 pb download, modified slightly, crashes.
The use of os.execute() w/in the pb lib stuff is where it fails...
any idea what I'm doing wrong?

Code: Select all

IncludeFile (#PB_Compiler_Home + "include\lua.pbi")

Global lua_state = lua_open() ; lua init

OpenConsole()

If lua_state
   luaopen_base(lua_state)	; base lib laden , fuer print usw
   
   luaString.s = "function test()"        + #LF$ ; test function
   luaString   + " os.execute("+#DQUOTE$+"c:\\windows\\system32\\notepad.exe"+#DQUOTE$+")" + #LF$	
   luaString   + " print(123456780)"		+ #LF$
   luaString   + " return 666,777"        + #LF$
   luaString   + "end"                    + #LF$
   
   MessageRequester("test",luaString)
   luaL_loadstring(lua_state, luaString)  ; script laden
   lua_pcall(lua_state, 0, 0, 0)  			; script starten
   
   lua_getglobal(lua_state, "test") 		; functionsname auf den stack packen
   lua_call(lua_state, 0, 2)					; function, die auf dem stack, aufrufe, mit 2 rueckgabe werten
	
	Debug lua_tointeger(lua_state, -1)     ; -1 erster  parameter
	Debug lua_tointeger(lua_state, -2)     ; -2 zweiter parameter
	
	lua_pop(lua_state, 1)                  ; stack saeubern
	
EndIf 
Input()
CloseConsole()