Created
July 6, 2016 13:04
-
-
Save jyrkive/bdcd77001a65d4d4fe276cc200574f86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char* TABLE_NAME = "functions"; | |
const char* FUNCTION_NAME = "my_lua_function"; | |
int my_lua_function(lua_State* L); | |
lua_State* L; | |
/* Assuming that the table exists already */ | |
/* Get the table */ | |
lua_getglobal(L, TABLE_NAME); | |
/* Push the function name */ | |
lua_pushstring(L, FUNCTION_NAME); | |
/* Register the function */ | |
lua_pushcfunction(L, my_lua_function); | |
/* Assign the function to the table */ | |
lua_settable(L, -3); | |
/* Remove the table from the stack (i.e. ensure that the stack is like before registering the function) */ | |
lua_pop(L, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment