#include <stdio.h>#include<math.h>#defineMax_color 255extern "C"{#include"Lua-5.2.2/src/lauxlib.h"#include"Lua-5.2.2/src/lualib.h"#include"lua-5.2.2/src/lstate.h"}/*parameter lua_state, the return value is the number of return values in the push result does not need to empty the stack, because there is a return value that represents the number of results, after the function returns LUA automatically clears the contents of the stack return results*/Static intL_sin (lua_state*L) { DoubleD = Lual_checknumber (L,1); Lua_pushnumber (L, sin (d)); return 1;}/*LUA registers the C library, passing the function names and corresponding functions pointers to LUA, and LUA uses table to store the information, which is also implemented by Lua's C libraries, which should be LUA global variables*/intMainintargcChar*argv[]) {Lua_state) O =lual_newstate ();///Quick and Dirty //function into the stacklua_pushcfunction (L, L_sin); //assign to Global, pop a value from the stack and set it to global variable MysinLua_setglobal (L,"Mysin"); GetChar (); return 0;}
LUA Registration function