發表文章

目前顯示的是有「lua」標籤的文章

lua call C function

C file : test.c ============================ #include <lua.h> #include <lauxlib.h> #include <lualib.h> #include <string.h> static int square( lua_State *L){               //用來取的lua參數,參數是以stack的狀態存在     float value = lua_tonumber (L, -1);       //轉型成C的型態     lua_pushnumber (L, value*value);         //回傳     return 1; } static int merge(lua_State *L){     const char *str1 = lua_tostring(L, -2);  //注意取的參數的順序     const char *str2 = lua_tostring(L, -1);     char str[80];     strcpy(str, str1);     strcat(str, str2); } int luaopen_ gg (lua_State *L){               // luaopen_*,載入時的主要進入點必需與.so和lua的lib同名     lua_register (L, "square", square);       //跟lua註冊function     lua_register(L, "cube", cube);     lua_register...