Return to Snippet

Revision: 9933
at November 30, 2008 21:24 by mjsmagalhaes


Initial Code
#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);
}

Initial URL
http://coderep.blogspot.com/2008/11/embedding-lua-in-cc-application-part-1.html

Initial Description
This is a hello world and the first of a series that shows how to embed Lua in a C/C++ application.

Initial Title
Hello World Using Lua Api

Initial Tags

                                

Initial Language
C