Load a Lua script into a table named after filename

Posted by Homeliss on Stack Overflow See other posts from Stack Overflow or by Homeliss
Published on 2010-04-28T06:21:44Z Indexed on 2010/04/28 6:33 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

I load scripts using luaL_loadfile and then lua_pcall from my game, and was wondering if instead of loading them into the global table, I could load them into a table named after their filename?

For example:

I have I file called "Foo.lua", which contains this:

function DoSomething()
    --something
end

After loading it I want to be able to access it like:

Foo.DoSomething()

Thanks!

© Stack Overflow or respective owner

Related posts about lua

Related posts about c