lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


When calling a C function from lua with a string argument, is that
string copied onto the stack that the C function gets? Or does the stack
contain a pointer to the original string? I am wondering about the most
efficient way to implement localisable string tables. I can see two ways
of doing this but I want to use the most efficient implementation. The
two methods can be boiled down to:

Method One:
-- StringTable.lua
stringtable = 
{
    mainmenu = "main",
    quit = "quit",
    yes = "yes"
}

-- SomeMenu.lua
require "StringTable"
callSomeCFunction(stringtable.yes)


Method Two:
-- StringTable.lua
LoadStringData("stringdata.bin")    -- loads the actual strings into a C
array

stringtable = 
{
    mainmenu = 1,
    quit = 2,
    yes = 3
}

-- SomeMenu.lua
require "StringTable"
callSomeCFunction(stringtable.yes)    -- integer argument indexes the C
array loaded earlier

- DC