fb:porticula NoPaste
luatest
Uploader: | flo |
Datum/Zeit: | 22.07.2008 17:45:55 |
'unsauber, geht aber
#include once "Lua/lua.bi"
#include once "Lua/lauxlib.bi"
#include once "Lua/lualib.bi"
dim shared as integer array(1 to 10)
function setvar cdecl (byval L as lua_State ptr) as integer
dim numpar as long
dim i as long
dim num as double
dim maxnum as double
dim minnum as double
' get the number of parameters passed on the virtual stack
' by the calling lua code
numpar = lua_gettop( L )
?">>",numpar
if numpar=2 then
array(lua_tonumber(L,1))=lua_tonumber(L,2)
lua_pushnumber( L, 1)
else
lua_pushnumber (L,0)
end if
' push the results on the vs
' set number of returned parameters
setvar = 1
end function
''
'' main
''
dim L as lua_State ptr
dim as integer i
' create a lua state
L = lua_open( )
' load the base lua library (needed for 'print')
luaopen_base( L )
' register the function to be called from lua as MinMax
lua_register( L, "setvar", @setvar )
for i=1 to 10
'?array(i)
next
?
?
' execute the lua script from a file
luaL_dofile( L, "/home/flo/programme/luatest/test0.lua" )
' release the lua state
lua_close( L )
for i=1 to 10
?array(i)
next
print "finished! press any key"
sleep
'--------------------------------------------------------
'jetzt die test0.lua (sorry für den absoluten pfad, er hat n bissl gesponnen
-- lua-datei:
print ("hallo!")
blubb = setvar (2,22)
blubb = setvar (1,1)
blubb = setvar (5,12345)
print ("----")
print (blubb)
-- das wars