Announcement

Collapse
No announcement yet.

Registration functions in LUA?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Registration functions in LUA?

    Help me please with registrationf functions in Lua.
    I'm using: Lua.dll, Lualib.dll and Lua_h.inc, Lualib_h.inc (c) Florent Heyworth

    Code:
    FUNCTION MyFunction CDECL ALIAS "MyFunction" (BYVAL L AS LUA_STATE) AS LONG
       LOCAL sMessage AS STRING
       sMessage = LUAL_CHECKSTRING(L,  1)  'tell Lua we need 1 string
       MSGBOX "Result: " + sMessage
       FUNCTION = 1  
    END FUNCTION
     
    FUNCTION libinit CDECL ALIAS "libinit" ( BYREF L AS LUA_STATE ) EXPORT AS LONG
       LUA_REGISTER(BYREF L, "MyFunction", CODEPTR(MyFunction) )
       FUNCTION = 0
    END FUNCTION
    This code works perfectly. Format of call function from Lua: Myfunction("Test").
    I need the format of call function from Lua: MyTable.MyFunction("Test")!

    Code:
    FUNCTION MyFunction CDECL ALIAS "MyFunction" (BYVAL L AS LUA_STATE) AS LONG
       LOCAL sMessage AS STRING
       sMessage = LUAL_CHECKSTRING(L,  1)  'tell Lua we need 1 string
       MSGBOX "Result: " + sMessage
       FUNCTION = 1  
    END FUNCTION
     
    FUNCTION libinit CDECL ALIAS "libinit" ( BYREF L AS LUA_STATE ) EXPORT AS LONG
       DIM LF1 AS ASCIIZ PTR
       DIM MyArray AS ASCIIZ PTR
       @MyArray = "MyTable"
       @LF1="MyFunction"
       DIM tab_funcs(2) AS LUAL_REG PTR
       @tab_funcs(1).pszname= LF1
       @tab_funcs(1).pfunc=CODEPTR(MyFunction)
       @tab_funcs(2).pszname=0
       @tab_funcs(2).pfunc=0   
     
       luaL_openlib(L,  @MyArray,  @tab_funcs(0), BYVAL 0)
       FUNCTION = 0
    END FUNCTION
    This code doesn't work. Please help me.

    P.S. I'm sorry for my bad English.
    Max Lapex
    Member
    Last edited by Max Lapex; 6 Mar 2008, 11:22 AM.
Working...
X