Skip to content

Commit

Permalink
Merge pull request #18 from Trey2k/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Trey2k authored Jul 27, 2021
2 parents 05046ef + 4680e46 commit 34dac9a
Show file tree
Hide file tree
Showing 71 changed files with 26,867 additions and 268 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,42 @@ Compiling
Examples
------------
**Running lua from a string:**
```
```gdscript
extends Node2D
onready var lua = Lua.new()
func _ready():
lua.doString("for i=1,10,1 do print('Hello lua!') end")
lua.do_string("for i=1,10,1 do print('Hello lua!') end")
```
<br />

**Running lua from a file:**
```
```gdscript
extends Node2D
onready var lua = Lua.new()
func _ready():
lua.doFile("user://luaFile.lua")
lua.do_file("user://luaFile.lua")
```
<br />

**Pushing a Variant as a global:**
```
```gdscript
extends Node2D
onready var lua = Lua.new()
var test = "Hello lua!"
func _ready():
lua.pushVariant(test, "str")
lua.doString("print(str)")
lua.push_variant(test, "str")
lua.do_string("print(str)")
```
<br />

**Exposing a GDScript function to lua:**
```
```gdscript
extends Node2D
onready var lua = Lua.new()
Expand All @@ -105,26 +105,26 @@ func luaAdd(a, b):
return a + b
func _ready():
lua.exposeFunction(self, "luaAdd", "add")
lua.doString("print(add(2, 4))")
lua.expose_function(self, "luaAdd", "add")
lua.do_string("print(add(2, 4))")
```
<br />

**Calling a lua function from GDScript:**
```
```gdscript
extends Node2D
onready var lua = Lua.new()
func _ready():
lua.doFile("user://luaFile.lua")
if( lua.luaFunctionExists("set_colours") ):
lua.callFunction( "set_colours", ["red", "blue"])
lua.do_file("user://luaFile.lua")
if( lua.lua_function_exists("set_colours") ):
lua.call_function( "set_colours", ["red", "blue"])
```
<br />

**Capturing lua errors:**
```
```gdscript
extends Node2D
onready var lua = Lua.new()
Expand All @@ -133,33 +133,33 @@ func luaCallBack(err):
print(err)
func _ready():
lua.doString("print(This wont work)", true , self, "luaCallBack")
lua.do_string("print(This wont work)", true , self, "luaCallBack")
```
<br />

**Enable threading:**
```
```gdscript
extends Node2D
onready var lua = Lua.new()
func _ready():
lua.setThreaded(true)
lua.doString("while true do print("The game will not freeze") end" )
lua.set_threaded(true)
lua.do_string("while true do print("The game will not freeze") end" )
```
<br />

**Kill all lua threads:**
```
```gdscript
extends Node2D
onready var lua = Lua.new()
func _ready():
lua.doString("while true do pass end")
lua.killAll()
lua.do_string("while true do pass end")
lua.kill_all()
```
Contributing And Feature Requests
---------------
Expand Down
26 changes: 15 additions & 11 deletions SCsub
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
Import('env')
#!/usr/bin/env python

env_lua = env.Clone()
env_lua.add_source_files(env.modules_sources, "*.cpp") #this will add all the cpp files
env_lua.Append(CPPPATH=["#modules/lua/luasrc/include"])
Import("env")
Import('env_modules')

if env['platform'] == "x11":
env.Append(LIBPATH=['#modules/lua/luasrc/libs/linux'])
elif env['platform'] == "windows":
env.Append(LIBPATH=['#modules/lua/luasrc/libs/windows'])
elif env['platform'] == "osx":
env.Append(LIBPATH=['#modules/lua/luasrc/libs/macos'])
env_lua = env_modules.Clone()

if not env.msvc:
env.Append(LIBS=['liblua'])
CXXFLAGS='-std=c++17'
else:
CXXFLAGS='/std:c++17'

env_lua['CXXFLAGS'] = [CXXFLAGS]

Export('env_lua')

SConscript('luasrc/SCsub')

env_lua.add_source_files(env.modules_sources,'*.cpp')
3 changes: 1 addition & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ def can_build(env, platform):
return True

def configure(env):
if env.msvc:
env.Append(LINKFLAGS='liblua.lib')
pass

def get_doc_classes():
return [
Expand Down
16 changes: 8 additions & 8 deletions docs/Lua.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<tutorials>
</tutorials>
<methods>
<method name="callFunction">
<method name="call_function">
<return type="void">
</return>
<argument index="0" name="LuaFunctionName" type="String">
Expand All @@ -27,7 +27,7 @@
Currently, getting returned values from this function is not available.
</description>
</method>
<method name="doFile">
<method name="do_file">
<return type="void">
</return>
<argument index="0" name="File" type="String">
Expand All @@ -42,7 +42,7 @@
Loads a files content as a string and calls [code]doString[/code] with it.
</description>
</method>
<method name="doString">
<method name="do_string">
<return type="void">
</return>
<argument index="0" name="Code" type="String">
Expand All @@ -57,7 +57,7 @@
Executes [code]Code[/code] as a piece of Lua code.
</description>
</method>
<method name="exposeFunction">
<method name="expose_function">
<return type="void">
</return>
<argument index="0" name="NodeObject" type="Object">
Expand All @@ -70,14 +70,14 @@
Defines a lua function with name [code]LuaFunctionName[/code]. When Lua code calls it, it will call the [code]GDFunction[/code] method of [code]NodeObject[/code], so make sure the object still exists at this moment.
</description>
</method>
<method name="killAll">
<method name="kill_all">
<return type="void">
</return>
<description>
Kills all current lua threads in execution.
</description>
</method>
<method name="luaFunctionExists">
<method name="lua_function_exists">
<return type="bool">
</return>
<argument index="0" name="LuaFunctionName" type="String">
Expand All @@ -86,7 +86,7 @@
Returns [code]true[/code] only if [code]LuaFunctionName[/code] is defined in current Lua's state as a function.
</description>
</method>
<method name="pushVariant">
<method name="push_variant">
<return type="bool">
</return>
<argument index="0" name="var" type="Variant">
Expand All @@ -96,7 +96,7 @@
<description>
</description>
</method>
<method name="setThreaded">
<method name="set_threaded">
<return type="void">
</return>
<argument index="0" name="bool" type="bool">
Expand Down
19 changes: 8 additions & 11 deletions lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ Lua::~Lua(){
static bool shouldKill = false;
// Bind C++ functions to GDScript
void Lua::_bind_methods(){
ClassDB::bind_method(D_METHOD("killAll"),&Lua::killAll);
ClassDB::bind_method(D_METHOD("setThreaded", "bool"),&Lua::setThreaded);
ClassDB::bind_method(D_METHOD("doFile", "File", "ProtectedCall" , "CallbackCaller" , "Callback" ), &Lua::doFile, DEFVAL(true) , DEFVAL(Variant()) , DEFVAL(String()) );
ClassDB::bind_method(D_METHOD("doString", "Code", "ProtectedCall" , "CallbackCaller" , "Callback" ), &Lua::doString, DEFVAL(true) , DEFVAL(Variant()) , DEFVAL(String()) );
ClassDB::bind_method(D_METHOD("pushVariant", "var"),&Lua::pushGlobalVariant);
ClassDB::bind_method(D_METHOD("exposeFunction", "NodeObject", "GDFunction", "LuaFunctionName"),&Lua::exposeFunction);
ClassDB::bind_method(D_METHOD("callFunction","LuaFunctionName", "Args", "ProtectedCall" , "CallbackCaller" , "Callback" ), &Lua::callFunction , DEFVAL(true) , DEFVAL(Variant()) , DEFVAL(String()) );
ClassDB::bind_method(D_METHOD("luaFunctionExists","LuaFunctionName"), &Lua::luaFunctionExists);
ClassDB::bind_method(D_METHOD("kill_all"),&Lua::killAll);
ClassDB::bind_method(D_METHOD("set_threaded", "bool"),&Lua::setThreaded);
ClassDB::bind_method(D_METHOD("do_file", "File", "ProtectedCall" , "CallbackCaller" , "Callback" ), &Lua::doFile, DEFVAL(true) , DEFVAL(Variant()) , DEFVAL(String()) );
ClassDB::bind_method(D_METHOD("do_string", "Code", "ProtectedCall" , "CallbackCaller" , "Callback" ), &Lua::doString, DEFVAL(true) , DEFVAL(Variant()) , DEFVAL(String()) );
ClassDB::bind_method(D_METHOD("push_variant", "var"),&Lua::pushGlobalVariant);
ClassDB::bind_method(D_METHOD("expose_function", "NodeObject", "GDFunction", "LuaFunctionName"),&Lua::exposeFunction);
ClassDB::bind_method(D_METHOD("call_function","LuaFunctionName", "Args", "ProtectedCall" , "CallbackCaller" , "Callback" ), &Lua::callFunction , DEFVAL(true) , DEFVAL(Variant()) , DEFVAL(String()) );
ClassDB::bind_method(D_METHOD("lua_function_exists","LuaFunctionName"), &Lua::luaFunctionExists);
}

// expose a GDScript function to lua
Expand Down Expand Up @@ -585,9 +585,6 @@ void Lua::handleError( lua_State* L , int lua_error ){
case LUA_ERRERR:
msg += "[LUA_ERRERR - error while handling another error ] ";
break;
case LUA_ERRGCMM:
msg += "[LUA_ERRGCM - error while running garbage collection ] ";
break;
default: break;
}
msg += lua_tostring(L,-1);
Expand Down
2 changes: 1 addition & 1 deletion lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "core/reference.h"
#include "core/bind/core_bind.h"

#include <lua.hpp>
#include "luasrc/lua.hpp"
#include <string>
#include <thread>
#include <mutex>
Expand Down
15 changes: 15 additions & 0 deletions luasrc/SCsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python

Import('env')
Import('env_lua')

env_lua = env_lua.Clone()

if env_lua['PLATFORM'] == 'posix':
env_lua.Append(CPPDEFINES='LUA_USE_POSIX')

if not env.msvc:
env_lua['CFLAGS'].remove('-std=gnu11')
env_lua.Append(CFLAGS=['-std=c99'])

env_lua.add_source_files(env.modules_sources,'*.c')
Loading

0 comments on commit 34dac9a

Please sign in to comment.