/ Published in: C
This is a hello world and the first of a series that shows how to embed Lua in a C/C++ application.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include "lua.h" #include "lualib.h" #include "lauxlib.h" int main() { // Create a context. This stores all variables and function available to Lua. lua_State * execContext = luaL_newstate(); // Adding Lua basic library luaL_openlibs(execContext); // Pushing the print function to the stack lua_getfield(execContext, LUA_GLOBALSINDEX, "print"); // Adding the first argument to the print function lua_pushstring(execContext,"Hello World !"); // print "Hello World !" // the state, number of args, number of returned values lua_call(execContext,1,0); // Cleaning the house lua_close(execContext); }
URL: http://coderep.blogspot.com/2008/11/embedding-lua-in-cc-application-part-1.html